// components/photo/photo.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        pic: "https://img2.baidu.com/it/u=2079741930,3055449139&fm=26&fmt=auto",
        src:"https://img2.baidu.com/it/u=2079741930,3055449139&fm=26&fmt=auto",
        items: [
            "地理定位",
            "拨打电话",
            "录音",
            "播放录音"

        ],
        latitude: "",
        longitude: ""

    },

    /**
     * 组件的方法列表
     */

    methods: {
        startPhoto(){
            const ctx = wx.createCameraContext()
            ctx.takePhoto({
              quality: 'high',
              success: (res) => {
                this.setData({
                  src: res.tempImagePath
                })
              }
            })
        },
        openaction() {
            wx.showActionSheet({
                itemList: this.data.items,
                success: (res) => {
                    wx.showToast({
                        icon: "success",
                        title: this.data.items[res.tapIndex] + " 成功"
                    })
                    if (res.tapIndex == 0) {
                        wx.getLocation({
                            type: 'wgs84',
                            success: (res) => {
                                const latitude = res.latitude
                                const longitude = res.longitude
                                const speed = res.speed
                                const accuracy = res.accuracy
                                this.setData({
                                    latitude,
                                    longitude
                                })
                                //  微信内置地图
                                wx.openLocation({
                                  latitude,
                                  longitude,
                                  scale:18
                                })
                            }
                        })
                    } else if (res.tapIndex == 1) {
                        wx.makePhoneCall({
                            phoneNumber: '13720231152' //仅为示例，并非真实的电话号码
                        })
                    } else if (res.tapIndex == 2) {
                        wx.startRecord({
                            success (res) {
                              const tempFilePath = res.tempFilePath
                            }
                          })
                          setTimeout(function () {
                            wx.stopRecord() // 结束录音
                          }, 10000)
                    } else {
                        
                    }
                },
                fail(res) {

                }
            })
        },

        takephoto(){
            wx.chooseImage({
              count: 1,
              sizeType: ['original', 'compressed'],
              sourceType: ['album', 'camera'],
              success: (res)=> {
                // tempFilePath可以作为img标签的src属性显示图片
                const tempFilePaths = res.tempFilePaths
                console.log(tempFilePaths)
                // this.uploadImgs(tempFilePaths[0])
                this.setData({
                  pic:tempFilePaths
                })
              }
            })
          },

        startScan() {
            wx.scanCode({
                success(res) {
                    console.log(res)
                }
            })
        }

    }
})